//
//  ViewController.m
//  AlicesPet
//
//  Created by de on 16/9/21.
//  Copyright © 2016年 de. All rights reserved.
//

#import "ViewController.h"
#import "ALSLoginTool.h"
#import "ALSShareTool.h"
#import "ALSPayTool.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (IBAction)weChatPay:(id)sender {
    
    NSURLSession *session = [NSURLSession sharedSession];
    NSString *urlString = [NSString stringWithFormat:@"http://219.136.249.101:8080/Ailisi/api/app/appCustomersAction_phoneLand?alias=123&phone=18675404057&password=123"];
    
    NSURL *url = [NSURL URLWithString:urlString];
    NSURLSessionTask *task = [session dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        
        if (!error) {
            
            NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            NSLog(@"%@",dict);
            NSString *sessionId = dict[@"sessionId"];
            NSString *token = dict[@"token"];
            NSString *urlString1 = [NSString stringWithFormat:@"http://219.136.249.101:8080/Ailisi/api/app/appWeiXinAction_sendPrepay?sessionId=%@&token=%@&price=1",sessionId,token];
            NSURL *url1 = [NSURL URLWithString:urlString1];
            
            NSURLSessionTask *task1 = [session dataTaskWithURL:url1 completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
                
                if (!error){
                
                    NSDictionary *resultDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                    NSLog(@"%@",resultDict);
                    NSDictionary *informationDict = resultDict[@"content"];
                    
                    //我就是支付啦
                    [ALSPayTool ALSPayInformation:informationDict PayType:weChatPay finished:^(ALSPayResponse *response) {
                        NSLog(@"%d",response.success);
                    }];
                }
            }];
            
            [task1 resume];
        }
    }];
    
    [task resume];

}

- (IBAction)share:(id)sender {
    [[ALSShareTool sharedInstence] ALSShareWebURL:@"https://www.taobao.com"
                                            title:@"爱立撕"
                                         subTitle:@"畅玩！就来爱立撕"
                                        imageName:@"ic_account_tyj"
                                         finished:^(BOOL success) {
         if (success) {
             NSLog(@"!!!!!!!!!!!!~~~~~~~%zdcheng",success);
             
         }else{
             
             //分享不成功，提示
             UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"失败" message:@"分享失败" delegate:nil cancelButtonTitle:@"好" otherButtonTitles: nil];
             [alertView show];
             //
             //                                                 NSLog(@"分享不成功");
         }
         
     }];

}

- (IBAction)wxLogin:(id)sender {
    
    [ALSLoginTool ALSLoginType:weChatLogin finished:^(ALSLoginResponse *response) {
        NSLog(@"微信%d~~~~~%@~~~~~%@~~~~%@",response.success,response.userInfo,response.uid,response.errorString);
    }];

}
- (IBAction)qqLogin:(id)sender {
    
    [ALSLoginTool ALSLoginType:qqLogin finished:^(ALSLoginResponse *response) {
        NSLog(@"QQ%d~~~~~~~~~%@~~~~~~~%@",response.success,response.userInfo,response.uid);
    }];
}
- (IBAction)wbLogin:(id)sender {
    
    [ALSLoginTool ALSLoginType:weiBoLogin finished:^(ALSLoginResponse *response) {
        NSLog(@"%d~~~~~~~~~%@~~~~~~~%@",response.success,response.userInfo,response.uid);
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
